// pages/help/select_other_family.js

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    family_list: []  //其它家族列表
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.httpRequest('get_family_list', {}, res => {
      console.log('family list: ', res)
      let family_list = []
      for (let i = 0; i < res.length; i++) {
        if (res[i].family_id != app.globalData.select_family_id) {
          family_list.push(res[i])
        } 
      }
      this.setData({
        family_list: family_list
      })
    }, res => {
      console.log('get family list failed: ', res)
    })
  },

  //选择家族
  familyRadioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)

    let items = this.data.family_list
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].family_id == e.detail.value
    }
  },

  bindConfirm(e) {
    let selectItem = null
    let items = this.data.family_list
    for (let i = 0, len = items.length; i < len; ++i) {
      if (items[i].checked) {
        selectItem = items[i]
        break
      }
    }

    if (!selectItem) {
      app.showTip('请选择一个家族')
      return
    }
    console.log('select family: ', selectItem)
    wx.navigateTo({
      url: '../help/select_other_family_member?family=' + selectItem.family_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  selectPersonCallback(select_family, select_person) {
    wx.navigateBack({
      delta: 0,
    })
    if (app.other_family_member_select_cb) {
      app.other_family_member_select_cb(select_family, select_person)
    }
  }
})